<?php

session_start();

/**
 * @author Janosch Hirth
 * @copyright 2013
 */
#echo ("<form action='".$_SERVER['SCRIPT_NAME']."' method='post'>\n");
echo("<link rel='stylesheet' type='text/css' href='styleTasks.css' media='all' />\n");
echo "<script type='text/javascript' src='tasks.js'></script>";
include 'nav.inc.php';
include 'dbConn.php';

html_head('Administration - Aufgabe bearbeiten');
echo "</head>\n<body>";

	if(!isset($_SESSION["username"])){					//kontrolliere ob Benutzer eingelogt ist
		echo("<div class='content' style='margin-left:350px'>");
	   echo ("Bitte erst <a href='../login.php'>einloggen</a>.");
	   exit;
	   echo("</div");
	}
	else
	{
		menu();
		echo("<div class='content' style='margin-left:350px'>");
		$aid = -1;
		if (isset($_REQUEST['AID']))
		{
			$aid = $_REQUEST['AID'];
		}
		if ($aid >-1)
		{
			$result = $dbAufgabe->get_Aufgaben_by_AID($aid);
			$task = mysql_fetch_array($result);
			$titel = $task['Titel'];
			$beschreibung = $task['Beschreibung'];
			$deadline = $task['Deadline'];
			$prioritaet = $task['Priorität'];
			$updateaid = $task['AID'];
		}
		if (isset($_REQUEST['next_page']))			//Seiten Variable
			$next_page = $_REQUEST['next_page'];
		else
			$next_page = '0';

		//Formular, zum eingeben der Daten
		echo ("<form id='modTask' name='modTask' action='".$_SERVER['SCRIPT_NAME']."' method='post'>\n");
		if($next_page == '0'){
			echo "\t<fieldset>
					<legend> Wähle Aufgabe</legend>";

			echo "<select id='members' name='members' size=25 onchange='showTaskInfo();'>";

			$Aufgaben = $dbAufgabe->get_Aufgaben ();
			while ($row = mysql_fetch_array($Aufgaben))
			{
				echo "<option value='".$row['AID']."'>".$row['Titel']."</option>";
			}
			echo "</select>
 				</fieldset>";
			echo "\t<fieldset>
				<legend id = taskinfolegend style= 'display:none;'>Aufgabe löschen</Legend>
				<ol id = 'taskinfo' style = 'display:none;' class='clearfix'>
					<li>
						<label for='titel'>Titel:</label>
						".$titel."
					</li>
					<li>
						<label for='beschreibung' style=backgroundcolor:'blue'>Beschreibung: </label>
						".$beschreibung."
					</li>
					<li>
						<label for='deadline'>Deadline: </label>
						".$deadline."
					</li>
					<li>
						<label for='prioritaet'>Priorität: </label>
						".$prioritaet."";
						
			echo "</li>";
			echo "<input type ='hidden' name='currentAID' id='currentAID' value='".$updateaid."'/>";
			echo "<input type='hidden' name='AID' id='AID' value='-1' />";		
			echo" 	<li class='last'>
      					<input type='submit' name='submitBTN' id='submitBTN' value='Aufgabe löschen' onclick='this.form.force.value=\"0\"' />
    				</li>
  				</ol>
  				</fieldset>";
			echo "\t</form>\n";

			if ($aid >-1) 
			{
				echo "<script type='text/javascript'>showNowForReal('".$aid."');</script>";
			}
			if (isset($_REQUEST['submitBTN']) AND isset($_REQUEST['currentAID']))
			{
				$AID = $_REQUEST['currentAID'];
				$delete = $dbAufgabe->DELETE_AUFGABE_BY_AID ($AID);
			}
		}
	}
echo "</div>";
echo "</body>";
?>
